Location
The global Location API provides access to the device’s geographic location, including one-time location retrieval, reverse geocoding, user-driven location selection via map, accuracy control, and permission checking for widgets.
Overview
This API allows you to:
- Request the device's current location
- Select a location manually using a map interface
- Reverse geocode latitude and longitude to address details
- Adjust location accuracy settings
- Check location access status for widgets
Note: This is a global API and does not require import.
API Reference
Location.isAuthorizedForWidgetUpdates(): Promise<boolean>
Checks whether widgets have permission to receive location updates.
Location.setAccuracy(accuracy: LocationAccuracy): Promise<void>
Sets the desired accuracy level for location retrieval. Higher accuracy may increase battery usage and wait time.
Parameters
Location.requestCurrent(options?: { forceRequest?: boolean }): Promise<LocationInfo | null>
Requests the user's current location once. May trigger a permission prompt if not previously granted.
By default, if a cached location is available, it will be returned immediately. If no cached location exists, a new request will be made. To force a new location retrieval even if a cached value exists, pass { forceRequest: true }.
Parameters
Location.pickFromMap(): Promise<LocationInfo | null>
Opens the built-in map interface to allow the user to manually select a location.
Location.reverseGeocode(options): Promise<LocationPlacemark[] | null>
Converts latitude and longitude into human-readable place information such as street, city, and country.
Parameters
Types
LocationAccuracy
Specifies the desired accuracy of location data:
LocationInfo
Represents a geographic coordinate with timestamp:
LocationPlacemark
Represents a human-readable description of a geographic coordinate, typically returned by reverse geocoding. Includes structured location details such as city, country, and street.
Field Descriptions
Example Usage
Reverse Geocode
Address Formatter (Helper)
Best Practices & Use Cases
- Use
areasOfInterestandnameto display user-friendly place names. - Use
postalCode,locality, andadministrativeAreafor autofill and geotagging. - Use
timestampto determine freshness of location data. - Use
timeZonefor localizing time-based features. - Set location accuracy before calling
requestCurrentfor optimal precision. - Always check widget permissions via
isAuthorizedForWidgetUpdates().
Notes
- Reverse geocoding may return multiple results. Use the first placemark for best relevance.
- If location retrieval fails,
nullis returned. - When
forceRequestis false or omitted, cached location may be used for faster results. - In widgets, location access may be restricted. Always verify permissions explicitly.
